package com.gljx.web.service.impl;

import com.gljx.util.TimeFormat;
import com.gljx.web.Entity.SimulationQuargentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SimulationQuargentryMapper;
import com.gljx.web.service.CustomLogService;
import com.gljx.web.service.SimulationQuargentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
@Service
@Transactional
public class SimulationQuargentryServiceImpl implements SimulationQuargentryService {
	@Autowired
	private SimulationQuargentryMapper simulationQuargentryMapper;

	@Autowired
	private CustomLogService customLogService;
	@Override
	public List<SimulationQuargentry> selectSimulationQuargentryByParentid(String fid,String studentName) {
		// TODO Auto-generated method stub
		return simulationQuargentryMapper.selectSimulationQuargentryByParentid(fid,studentName);
	}
	@Override
	public int addSimulationQuargentry(SimulationQuargentry simulationQuargentry) {
		// TODO Auto-generated method stub
		return simulationQuargentryMapper.insertSelective(simulationQuargentry);
	}
	@Override
	public int deleteByParentId(String parentid, User user) {
		// TODO Auto-generated method stub
		if(user != null){
			//根据父类id查找子类信息
			List<SimulationQuargentry> simulationQuargentries =simulationQuargentryMapper.selectSimulationQuargentryByParentid(parentid,null);
			for (int i = 0; i < simulationQuargentries.size(); i++) {
				//添加学员的服务日志
				customLogService.addLog("考试管理", TimeFormat.timeFormat(new Date()) + "删除了学员"+simulationQuargentries.get(i).getStudentName()+"模拟考合格登记!成绩:"+simulationQuargentries.get(i).getCfgrade(),
						simulationQuargentries.get(i).getCfstudentid(), user.getFid());
			}
		}
		return simulationQuargentryMapper.deleteByParentId(parentid);
	}
	@Override
	public SimulationQuargentry selectByPrimaryKey(String fid) {
		// TODO Auto-generated method stub
		return simulationQuargentryMapper.selectByPrimaryKey(fid);
	}

}
